package scau.hotel.hotel_web.controller;

import org.springframework.security.authentication.CredentialsExpiredException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 过滤器异常controller
 * @program: fire_control
 * @description:
 * @author: fbl
 * @create: 2021-01-18 07:54
 **/
@RestController
public class JwtExceptionController {

    /**
     * 重新抛出异常
     */
    @RequestMapping("/credentialsExpiredException")
    public void credentialsExpiredException(HttpServletRequest request) throws CredentialsExpiredException {
        if (request.getAttribute("credentialsExpiredException") instanceof CredentialsExpiredException) {
            throw ((CredentialsExpiredException) request.getAttribute("credentialsExpiredException"));
        } else {
            throw new CredentialsExpiredException("用户缓存有效期已过，请重新登录");
        }
    }



}

